//删除未上传的文件
function removeFile(filename){
	$.ajax({
            type: 'post',
            url: $("#basePath").val()+'/pages/TUpload/delete.do',
            data: {'Filename':filename},
            success: function (msg) {
            	if(msg.success){
            		$.messager.alert('提示', "删除成功");
            	}else{
            		$.messager.alert('提示', "删除失败");
            	}
            }
      });
}
//加载上传组件
$(function(){
	$('#uploadFile').uploadify({
		buttonText:'上传文件',
		auto:true,
		simUploadLimit:3,
		method:'post',
		progressData:'speed',
		multi:true,
		removeCompleted:false,//是否移除已经上传的文件
		height:25,
		overrideEvents:['onDialogClose'],fileTypeDesc:'文件格式:',
		queueID:'filediv',fileTypeExts:$("#filetype").val(),
		fileSizeLimit:'15MB',swf:$("#basePath").val()+'/efile/style/uploadify.swf',	
		uploader:$("#basePath").val()+'/efile/FileManageUploadSave.do',
		onUploadStart : function(file) { 
			var parentid=$('#parentid').val();$('#uploadFile').uploadify("settings", "formData", {'parentid':parentid});
		} ,
		onQueueComplete : function(queueData) {
		},
		onSWFReady:function(file){
			uploadifyQueueData = this.queueData;
		},
		onUploadSuccess : function(file, data, response) {
			var d=$.parseJSON(data);
			var ids = file.id.split("_");
			var tab = $("#upload_tab");
			var tr = $("<div style='display:none'></div>");
			tr.attr("id",file.id+"tr");
			var oldnameInput = $("<input type='hidden' id='oldname"+file.id+"' name='list["+ids[2]+"].fileoldname' >");
			oldnameInput.val(d.oldname);
			var newInput = $("<input type='hidden' id='newname"+file.id+"' name='list["+ids[2]+"].filenewname' value="+d.newname+">");
			var sizeInput = $("<input type='hidden' id='newname"+file.id+"' name='list["+ids[2]+"].filesize' value="+d.size+">");
			tr.append(oldnameInput);
			tr.append(newInput);
			tr.append(sizeInput);
			tab.append(tr);
		},
		uploadifyCancel: function(file){    
			alert("取消文件：" + file.name);    
		},
		onFallback : function(){
			tip("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试")
		},
		onSelectError : function(file, errorCode, errorMsg){
			switch(errorCode) {case -100:tip("上传的文件数量已经超出系统限制的"+$('#uploadFile').uploadify('settings','queueSizeLimit')+"个文件！");break;case -110:tip("文件 ["+file.name+"] 大小超出系统限制的"+$('#uploadFile').uploadify('settings','fileSizeLimit')+"大小！");break;case -120:tip("文件 ["+file.name+"] 大小异常！");break;case -130:tip("文件 ["+file.name+"] 类型不正确！");break;}
		},
		onUploadProgress : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { 
		}
	});
});
//用于弹出页面关闭时销毁flash
function destro(){
	if($(".uploadify-queue-item").length>0){
		$('#file_upload').uploadify('cancel');
	}
	$("#file_upload").uploadify("destroy");
}
//删除已经上传的文件
function delUpload(id){
        $.ajax({
            type: 'post',
            url: $("#basePath").val()+'/pages/TUpload/deleteExsitFile.do',
            data: {'id':id},
            success: function (msg) {
            	if(msg.success){
            		$("#"+id).remove();
            		parent.alert("删除成功");
            	}else{
            		parent.alert("删除失败");
            	}
            }
        });
}